package com.zyj.guava.partition;

import com.google.common.collect.Lists;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class PartitionSample {

    public static void main(String[] args) {
        List<Integer> userIdList = getUserIdList();
        List<List<Integer>> partitions = Lists.partition(userIdList, 10);
        for (List<Integer> partition : partitions) {
            List<String> strings = queryDB(partition);
            System.out.println(strings);
        }
    }

    //查询100个用户id
    public static List<Integer> getUserIdList() {
        return IntStream.range(0, 100).boxed().collect(Collectors.toList());
    }

    //根据用户id查询用户信息
    public static List<String> queryDB(List<Integer> userIdList) {
        if (userIdList.size() > 10) {
            throw new RuntimeException("数据库连接超时");
        }
        return userIdList.stream().map(String::valueOf).collect(Collectors.toList());
    }
}
